'use strict';
const db = uniCloud.database();
const memoCollection = db.collection('memo');

exports.main = async (event, context) => {
  try {
    // 从 event 中获取模糊查询的关键词
    const { keyword } = event;
    // 使用正则表达式进行模糊查询，i 表示不区分大小写
    const res = await memoCollection.where({
      title: new RegExp(keyword, 'i')
    }).get();
    return {
      code: 200,
      message: '模糊查询备忘录成功',
      data: res.data
    };
  } catch (error) {
    return {
      code: 500,
      message: '模糊查询备忘录失败',
      error: error.message
    };
  }
};